﻿using System.Data;

namespace DataServer.ApplicationLib.Rules
{
    public class ConfigDataRuleRow : ConfigDataRuleBase
    {
        public ConfigDataRuleRow(RuleContext ruleContext) : base(ruleContext)
        {
        }

        public async override Task<VerifyRuleResult> VerifyData()
        {
            VerifyRuleResult result = new VerifyRuleResult()
            {
                IsValid = true
            };
            DataTable data = this.RuleContext.TargetData;
            if (null != data && data.Rows.Count > 0)
            {
                result = RunByRuleType(data, RuleType.RowRule, false);
                if (this.Successor != null)
                {
                    var successorResult = await this.Successor.VerifyData();
                    result.Message += successorResult.Message;
                }
            }
            else
            {
                result.Message = "数据列表为空，不需要进行校验";
            }
            result.IsValid = string.IsNullOrEmpty(result.Message);

            return result;
        }
    }
}
